//
//  DEWLikeCommentTableCell.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/25.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWLikeCommentTableCell.h"

@interface DEWLikeCommentTableCell()
///回复按钮
@property (nonatomic ,strong) UIButton *commentBtn;
///头像
@property (nonatomic ,strong) UIImageView *headerImageV;
///认证图标
@property (nonatomic ,strong) UIImageView *believeImageV;
///name
@property (nonatomic ,strong) UILabel *nameLab;
@property (nonatomic ,strong) UILabel *dateLab;
///楼位
@property (nonatomic ,strong) UILabel *floorLab;
///回复内容
@property (nonatomic ,strong) UILabel *commentLab;
///正文图片
@property (nonatomic ,strong) UIImageView *descImageV;
///正文
@property (nonatomic ,strong) UILabel *descLab;

@end

@implementation DEWLikeCommentTableCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView
{
    ///头像
    UIImageView *headerImgV = [[UIImageView alloc]init];
    headerImgV.backgroundColor = WhiteColor;
    _headerImageV = headerImgV;
    [self.contentView addSubview:headerImgV];
    _believeImageV = [[UIImageView alloc]init];
    _believeImageV.backgroundColor = WhiteColor;
    [self.contentView addSubview:_believeImageV];
    ///名称
    UILabel *nameLab = [[UILabel alloc]init];
    nameLab.font = [UIFont systemFontOfSize:15.0f];
    nameLab.textColor = Color_33;
    _nameLab = nameLab;
    [self.contentView addSubview:nameLab];
    ///名称
    UILabel *floorLab = [[UILabel alloc]init];
    floorLab.font = [UIFont systemFontOfSize:15.0f];
    floorLab.textColor = [UIColor whiteColor];
    _floorLab = floorLab;
    floorLab.layer.cornerRadius = 4.0f;
    _floorLab.layer.masksToBounds = YES;
    [self.contentView addSubview:floorLab];
    
    ///时间
    UILabel *dateLab = [[UILabel alloc]init];
    dateLab.font = [UIFont systemFontOfSize:11.0f];
    dateLab.textColor = UIColorFromRGB(0xAAAAAA);
    _dateLab = dateLab;
    [self.contentView addSubview:dateLab];
    ///回复按钮
    _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_commentBtn setTitleColor:Color_99 forState:UIControlStateNormal];
    _commentBtn.layer.cornerRadius = 4.0f;
    _commentBtn.layer.borderColor = UIColorFromRGB(0xDCDCDC).CGColor;
    _commentBtn.layer.borderWidth = 1.0f;
    _commentBtn.layer.masksToBounds = YES;
    [_commentBtn addTarget:self action:@selector(commentFriendWords) forControlEvents:UIControlEventTouchUpInside];
    [_commentBtn setTitle:@"回复" forState:UIControlStateNormal];
    _commentBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_commentBtn];
    ///回复内容
    UILabel *commentLab = [[UILabel alloc]init];
    commentLab.textColor = Color_33;
    commentLab.font = [UIFont systemFontOfSize:16.0f];
    _commentLab = commentLab;
    [self.contentView addSubview:commentLab];
    ///帖子内容
    UIImageView *descImageV = [[UIImageView alloc]init];
    descImageV.backgroundColor = WhiteColor;
    _descImageV = descImageV;
    [self.contentView addSubview:descImageV];
    ///
    UILabel *descLab = [[UILabel alloc]init];
    descLab.textColor = Color_66;
    descLab.numberOfLines = 2;
    descLab.font = [UIFont systemFontOfSize:12.0f];
    _descLab = descLab;
    [self.contentView addSubview:descLab];
}

-(void)setModel:(DEWLikeComentModel *)model
{
    _model = model;
    [self setupViewFrameWithInfo:model];
}


-(void)setupViewFrameWithInfo:(DEWLikeComentModel *)model
{
    ///头像
    [_headerImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_URLIMAGE,model.avatarUri]] placeholderImage:kDefalutUserHeader];
    _believeImageV.image = [UIImage imageNamed:@"LJ等级"];
    ///name
    _nameLab.text = model.nickName;
    
    
    
    ///楼位
    _floorLab.text = model.building;
    ///内容
    NSString *commentStr = [NSString FMAT:model.content];
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:commentStr];
    _commentLab.attributedText = attributeStr;
    ///正文图片
    NSString *descImgStr = [NSString FMAT:model.picurl];
    CGFloat descImgWH = 50.0f;
    
    
    _dateLab.text = [DateHelper getTimeWithTimeIntervalString:model.createTime];
    ///正文
    _descLab.text = [NSString FMAT:model.title];
    
    ///---------------设置frame-----------
    CGFloat imgWH = 40.0f;
    _headerImageV.frame = CGRectMake(Margin_15, Margin_15, imgWH, imgWH);
    _headerImageV.layer.cornerRadius = imgWH/2;
    _headerImageV.layer.masksToBounds = YES;
    _headerImageV.layer.borderColor = CellLineColor.CGColor;
    _headerImageV.layer.borderWidth = 1.0f;
    if ([model.isApprove isEqualToString:@"1"]) {///已认证
        _believeImageV.Wbotoom = _headerImageV.Wbotoom-13;
        _believeImageV.size = CGSizeMake(13, 13);
        _believeImageV.right = _headerImageV.right;
        _believeImageV.layer.cornerRadius = 13/2;
        _believeImageV.layer.masksToBounds = YES;
    }
    
    
    CGFloat btnW = 60.0f;
    
    CGFloat nameMaxW = Device_Width-_headerImageV.right-10-btnW-Margin_15-65.0f;
    
    ///name
    CGSize size = [model.nickName sizeWithFont:[UIFont systemFontOfSize:15.0f] maxSize:CGSizeMake(nameMaxW, 21.0f)];
    _nameLab.frame = CGRectMake(_headerImageV.right+10.0f, Margin_15, size.width+10, 21.0f);
    
    if ([model.kinds isEqualToString:@"1"]) {
        ///评论
        _commentBtn.frame = CGRectMake(DEWScreenWidth-btnW-Margin_15, Margin_15, btnW, 25.0f);
    }
    
    
    ///楼层
    
    CGSize floorSize = [model.building sizeWithFont:[UIFont systemFontOfSize:15.0f] maxSize:CGSizeMake(65, 15)];
//    [model.building sizeWithText:[UIFont systemFontOfSize:15.0f] maxW:CGSizeMake(65, 15)];
    
    _floorLab.frame = CGRectMake(_nameLab.right+10, Margin_15+2, floorSize.width+4, 17.0f);
    
    ///时间
    _dateLab.frame = CGRectMake(_nameLab.left, _nameLab.bottom+4, Device_Width/2, 15.0f);
    ///评论
    CGFloat commentH = model.cellHeight-149;
    _commentLab.frame = CGRectMake(_nameLab.left, _dateLab.bottom+13.0f, Device_Width-_nameLab.left-Margin_15, commentH);
    if (![BaseUtils isBlankString:descImgStr]) {
        [_descImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_URLIMAGE,descImgStr]] placeholderImage:defalutImage];
        
        _descImageV.frame = CGRectMake(_nameLab.left, _commentLab.bottom+Margin_15, descImgWH, descImgWH);
    }
    ///内容图片大小
    _descLab.frame = CGRectMake(_commentLab.left+ _descImageV.width, _commentLab.bottom+Margin_15, Device_Width-_nameLab.left-Margin_15-_descImageV.width, descImgWH);
    
    _floorLab.backgroundColor = UIColorFromRGB(0x44D5A6);
    _descLab.backgroundColor = UIColorFromRGB(0xF9F9F9);
    
}


///回复
- (void)commentFriendWords
{
    if (_likeDelegate && [_likeDelegate respondsToSelector:@selector(didCellAtIndexPath:andInfo:)]) {
        [_likeDelegate didCellAtIndexPath:self.indexPath andInfo:self.model];
    }
    
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
